<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <textarea name="" id="text" cols="30" rows="10"> </textarea
    ><button>提交</button>
    <div></div>

    <div class="zks">1322</div>
  
    <script>
      //  \s
      // 匹配空白字符；

      // \S
      // 匹配非空白字符；
      // 传统方式
     


      // 正则表达式方式----字符串.replace(/xxx/,"xxx")
      // 注意：正则表达式最后跟上g表示全部匹配，i表示忽略大小写   m多行
      var text = document.querySelector("#text");
      var btn = document.querySelector("button");
      var div = document.querySelector("div");



      var arr = ["fuck", "张可顺", "S", "zks"];

      btn.addEventListener("click", function () {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i] === text.value) {
            return div.innerHTML = text.value.replace(new RegExp(arr[i],'gi'), "***");;
          } else {
            div.innerHTML = text.value;
          }
        }
      });

    

      const zks = document.querySelector(".zks");
      zks.innerHTML = zks.innerHTML.replace(/^(\S{1})\S{2}(\S{1})/, "$1****$2");

// 替换文字html格式

const textHtml="<div >我是谁</div>"
const temp=textHtml.replace(/<[^]+>/g,'')
console.log(temp);
    </script>
  </body>
</html>